package com.weharvest.edu.config;

import me.chanjar.weixin.mp.api.WxMpConfigStorage;
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 配置开放平台信息
 */
@Component
public class WechatOpenConfig {

    @Resource
    private   WechatConfig wechatConfig;

    @Bean
    public WxMpService wxOpenService(){
        WxMpService wxMpService=new WxMpServiceImpl();
        wxMpService.setWxMpConfigStorage(wxOpenConfigStorage());
        return wxMpService;
    }

    @Bean
    public WxMpConfigStorage wxOpenConfigStorage(){
        WxMpInMemoryConfigStorage wxMpInMemoryConfigStorage=new WxMpInMemoryConfigStorage();
        wxMpInMemoryConfigStorage.setAppId(wechatConfig.getOpenAppId());
        wxMpInMemoryConfigStorage.setSecret(wechatConfig.getOpenAppSecret());
        return  wxMpInMemoryConfigStorage;
    }
}
